package com.ruoyi.course.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.course.vo.ExamCourseBankVo;
import com.ruoyi.course.service.IExamCourseBankService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 课程题库关系Controller
 *
 * @author Tellsea
 * @date 2025-10-15
 */
@Api(tags = "课程题库关系Controller")
@RestController
@RequestMapping("/course/courseBank")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class ExamCourseBankController extends BaseController {

    private final IExamCourseBankService examCourseBankService;

    @ApiOperation("查询课程题库关系列表")
    @GetMapping("/list")
    public TableDataInfo<ExamCourseBankVo> list(ExamCourseBankVo entity) {
        return examCourseBankService.queryList(entity);
    }

    @ApiOperation("查询课程题库关系所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(ExamCourseBankVo entity) {
        return AjaxResult.success("查询成功", examCourseBankService.queryAll(entity));
    }

    @ApiOperation("导出课程题库关系列表")
    @Log(title = "课程题库关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExamCourseBankVo entity) {
        List<ExamCourseBankVo> list = examCourseBankService.queryAll(entity);
        ExcelUtil<ExamCourseBankVo> util = new ExcelUtil<>(ExamCourseBankVo.class);
        util.exportExcel(response, list, "课程题库关系数据");
    }

    @ApiOperation("获取课程题库关系详细信息")
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success("查询成功", examCourseBankService.queryById(id));
    }

    @ApiOperation("新增课程题库关系")
    @Log(title = "课程题库关系", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody ExamCourseBankVo entity) {
        return toAjax(examCourseBankService.save(entity));
    }

    @ApiOperation("修改课程题库关系")
    @Log(title = "课程题库关系", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody ExamCourseBankVo entity) {
        return toAjax(examCourseBankService.updateById(entity));
    }

    @ApiOperation("删除课程题库关系")
    @Log(title = "课程题库关系", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(examCourseBankService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
